/**
 * 试算基础类
 *
 * @class Trial
 */

import * as Utils from './index';

interface GeneList {
    [key: string]: any
}

interface TrialData {
    [key: string]: any
}

class Trial {
    // 内部变量
    trialData: TrialData;
    geneList: GeneList;

    // 初始化信息
    constructor(trialData: object) {
        this.trialData = trialData;
        this.geneList = Utils.getGeneList(this.trialData, 'geneList');
    }

    /**
     * 获取试算信息
     *
     * @return {*} 
     * @memberof Trial
     */
    getTrialData() {
        return this.trialData;
    }

    /**
     * 获取试算信息 
     * 为了兼容历史问题，需兼容key/geneKey/protectItemId 匹配
     * 
     * @return {*} 
     * @memberof Trial
     */
    getTrialGeneByKey(keyCode: string) {
        let gene = this.geneList.find((item: { key: string; }) => (item.key === keyCode));
        if (!gene) {
            gene = this.geneList.find((item: { geneKey: string; }) => (item.geneKey === keyCode));
        }
        if (!gene) {
            gene = this.geneList.find((item: { protectItemId: string; }) => (item.protectItemId === keyCode));
        }
        return gene;
    }





}

export default Trial;
